//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    phone:"",
    userout:false,
    motto: '记得，按时吃饭',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        userout:true,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true,
          userout:true,
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true,
            userout:true,
          })
        }
      })
    }
  },
  getUserInfo: function(e) {
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userout:true,
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
    wx.navigateTo({
      url: '/pages/index/login/login',
    })
  },
  out:function(){
    this.setData({
      userout:false,
      hasUserInfo: false
    })
    wx.removeStorage({
      key: 'session',
      key: 'sessionid',
    })
  },
  location:function(){
    let that=this
    let phone=that.data.phone
    wx.navigateTo({
      url: '/pages/index/infor/location/location?phone='+[phone],
    })
  },
  message:function(){
    let that=this
    let phone=that.data.phone
    wx.navigateTo({
      url: '/pages/index/Mymessage/message?phone='+[phone],
    
    })
  },
})
